package com.kmxd.ams.core.common.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.kmxd.ams.core.common.constant.ErrorCode;
import com.kmxd.ams.core.exception.BizException;
import java.util.Arrays;
import java.util.Objects;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 实体登记类型
 *
 * @author nickbi
 */
@Getter
@AllArgsConstructor
public enum RegistrationInEntityEnum {
  /** 出库 */
  S1("1", "缺损登记-污损"),
  S2("2", "缺损登记-虫蛀"),
  S3("3", "缺损登记-丢失"),
  S4("4", "增加实体-打印"),
  S5("5", "增加实体-复印"),
  S6("6", "增加实体-接收入库"),
  S7("7", "缺损登记-宗外移交 （减少）"),
  S8("8", "增加实体-复制移交档案"),
  S9("9", "增加实体-宗外接收 （增加）"),
  ;

  private String code;
  private String desc;

  public static RegistrationInEntityEnum convert(String type) {
    return Arrays.stream(values())
        .filter(x -> x.code.equals(type))
        .findAny()
        .orElseThrow(() -> BizException.instance(ErrorCode.NOT_FOUND, "未找到出入库类型：" + type));
  }

  @JsonCreator
  public static RegistrationInEntityEnum getValue(String type) {
    return Arrays.stream(values()).filter(x -> Objects.equals(x.code, type)).findAny().orElse(null);
  }
}
